package com.app.base.config.exception;



import com.app.base.utlis.result.Result;
import com.app.base.utlis.result.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

@Slf4j
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.error().message("服务器又耍流氓了..");
    }


    @ExceptionHandler(SaaSException.class)
    public Result error(SaaSException e) {
        return Result.error().code(e.getCode()).message(e.getMsg());
    }

    @ExceptionHandler(IOException.class)
    public Result error(IOException e) {
        throw SaaSException.from(String.valueOf(ResultCode.ERROR));
    }
}
